package com.wyix.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.MatrixVariable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author wangdx
 * @since 2025/8/8
 */
@Controller
public class OrderController {

    // 多层级订单查询，支持多路径矩阵变量
    @GetMapping("/users/{userId}/orders/{orderId}/items/{itemId}")
    @ResponseBody
    public String orderItemDetail(
            // 路径变量
            @PathVariable String userId,
            @PathVariable String orderId,
            @PathVariable String itemId,

            // 用户层级矩阵变量（与userId关联）
            @MatrixVariable(pathVar = "userId") String memberLevel,

            // 订单层级矩阵变量（与orderId关联）
            @MatrixVariable(pathVar = "orderId") String status,
            @MatrixVariable(pathVar = "orderId") List<String> tags,

            // 商品项层级矩阵变量（与itemId关联），映射为Map
            @MatrixVariable(pathVar = "itemId") Map<String, String> itemProps
    ) {
        StringBuilder result = new StringBuilder();
        result.append("用户ID：").append(userId).append("，会员等级：").append(memberLevel).append("\n");
        result.append("订单ID：").append(orderId).append("，状态：").append(status)
                .append("，标签：").append(tags).append("\n");
        result.append("商品ID：").append(itemId).append("，属性：").append(itemProps);

        return result.toString();
    }
}
